//
//  InformationModel.m
//  APP_login
//
//  Created by edz on 7/5/21.
//  Copyright © 2021 baicai. All rights reserved.
//

#import "InformationModel.h"
#import "UserSingleton.h"

@implementation InformationModel

//存对象
- (void) encodeWithCoder:(NSCoder *)coder{
    [coder encodeObject:self.nickName forKey:@"nickName"];
    [coder encodeInteger:self.gender forKey:@"gender"];
    [coder encodeObject:self.birthday forKey:@"birthday"];
    [coder encodeObject:self.describe forKey:@"describe"];
    [coder encodeObject:self.leranTagArray forKey:@"tagArray"];
}

//取对象
- (instancetype)initWithCoder:(NSCoder *)coder{
    if (self = [super init]) {
        self.nickName = [coder decodeObjectForKey:@"nickName"];
        self.gender = [coder decodeIntegerForKey:@"gender"];
        self.birthday = [coder decodeObjectForKey:@"birthday"];
        self.describe = [coder decodeObjectForKey:@"describe"];
        self.leranTagArray = [coder decodeObjectForKey:@"tagArray"];
    }
    return self;
}

+ (BOOL)supportsSecureCoding{
    return YES;
}

- (void)writeData{
    NSError *error;
    NSData *data = [NSKeyedArchiver archivedDataWithRootObject:self requiringSecureCoding:YES error:&error];
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    [user setObject:data forKey:@"userModel"];
}

+ (instancetype)readData{
    NSError *error;
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSData *data = [user objectForKey:@"userModel"];
    InformationModel *model = [NSKeyedUnarchiver unarchivedObjectOfClass:[InformationModel class] fromData:data error:&error];
    return model;
}
@end
